package com.tintintech.sendmail.helper;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.tintintech.sendmail.Config;

public class FileHelper {

	public static void remove(String uri)
	{
		File f = new File(uri);
		
		if (f.isFile())
		{
			f.delete();
		}
		else if (f.isDirectory())
		{//不需要更深层的删除
			for (File _f : f.listFiles())
			{
				if (_f.isFile())
				{
					_f.delete();
				}
			}
		}
	}
	
	public static void recordLog(String email, String uri)
	{
		if (uri == null)
		{
			uri = Config.GLOBALS.get("logPath") + Config.GLOBALS.get("logFailName");
		}
		File f = new File(uri);
		if (f.isFile() == false)
		{
			try {
				f.createNewFile();
			} catch (Exception e) {
				System.out.println("create logFail file failed!");
			}
		}
		
		try {
			FileWriter fw = new FileWriter(uri, true);
			fw.write(email + "\n");
			fw.flush();
			fw.close();
		} catch (IOException ioe) {
			
		}
	}
}
